import java.util.Vector;

import javax.microedition.lcdui.Command;
import javax.microedition.lcdui.CommandListener;
import javax.microedition.lcdui.Image;
import javax.microedition.lcdui.List;

public class Buddy {
	//Status values
	public static final int STATUS_OFFLINE 	= 0x00000000;
	public static final int STATUS_AWAY 	= 0x00000001;
	public static final int STATUS_BUSY 	= 0x00000002;
	public static final int STATUS_ONLINE 	= 0x00000003;
	public static final int STATUS_UNREAD 	= 0x00010000;
	
	public static Image in_img;
	public static Image out_img;
	
	String jid;
	String name;
	int status;
	Vector messages;
	List messageList;
	
	public Buddy(String id, String buddyName, int buddyStatus) {
		this.jid = id;
		if (buddyName != null) {
			this.name = buddyName;
		} else {
			this.name = id;
		}
		this.status = buddyStatus;
	}
	
	public List getMessageList(Command backCommand, CommandListener l) {
		if (messageList == null) {
			messages = new Vector();
			messageList = new List("Chat with " + this.name, List.IMPLICIT);
			messageList.addCommand(backCommand);
			messageList.setCommandListener(l);
			messageList.append("New message", null);
		}
		
		return messageList;
	}
	
	public void sentMessage(String msg) {
		messages.addElement(msg);
		messageList.append(msg, out_img);
		messageList.setSelectedIndex(messageList.size()-1, true);
	}
	
	public void receivedMessage(String msg) {
		messages.addElement(msg);
		messageList.append(msg, in_img);
		messageList.setSelectedIndex(messageList.size()-1, true);
	}
}
